﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;
namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 小区状况DAL
    /// </summary>
    public class Collateral_CommunityDAL : GenericBaseDAL<Collateral_Community>
    {
        /// <summary>
        /// 根据报告号去查询小区是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int IsCount(string P_ReportNumber)
        {
            int C_projectcount;
            string sql = @"select count(T_CommunityID) from Collateral_Community  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }
        /// <summary>
        /// 根据报告号去查询小区的信息
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public Collateral_Community Community(string P_ReportNumber)
        {
            Collateral_Community munity = new Collateral_Community();
            string sql = @"select * from Collateral_Community  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            munity.T_ReportNumber = reader["T_ReportNumber"].ToString();
                            munity.T_Project = reader["T_Project"].ToString();
                            munity.T_SourceID = Convert.ToInt32(reader["T_SourceID"]);
                            // munity = reader["C_source"].ToString();
                            munity.T_CloseID = Convert.ToInt32(reader["T_CloseID"]);
                            munity.T_BuildingID = Convert.ToInt32(reader["T_BuildingID"]);
                            munity.T_TrafficZuzhiID = Convert.ToInt32(reader["T_TrafficZuzhiID"]);
                            munity.T_AfforestID = Convert.ToInt32(reader["T_AfforestID"]);
                            munity.T_VolumeID = Convert.ToInt32(reader["T_VolumeID"]);
                            munity.T_StallID = Convert.ToInt32(reader["T_StallID"]);
                            munity.T_PropertyID = Convert.ToInt32(reader["T_PropertyID"]);
                            munity.T_Else = reader["T_Else"].ToString();
                            //   munity. = Convert.ToInt32(reader["C_state"]);

                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return munity;
            }
        }
    }
}
